//    OSRail -- a network enabled railroad operations simulator and utilities
//    Copyright (C) 2007,2008 Samuel E. Henley sehenley@comcast.net
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License along
//    with this program; if not, write to the Free Software Foundation, Inc.,
//    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// cmakefilter.cpp

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

/// \addtogroup tools "Conversion Tools and Utilities"
/// @{
///   \addtogroup doxygenfilter "CMake DOxygen Filter Files"
///   @{


/// \file
/// Doxygen filter for cmake files.
/// The filter is intended for CMakeList.txt and *.cmake files.
/// In the Doxyfile add *.cmake, and *.txt to the
/// FILE_PATTERNS. FILTER_PATTERNS =
/// *.cmake=cmakefilter *.txt=cmakefilter should also be set.

static const char version[] = "$Id$";

int main(int argc, char* argv[])
{
    if( argc < 2 )exit(1);

    ifstream cmakefile( argv[1] );

    istreambuf_iterator<char> it(cmakefile);
    const istreambuf_iterator<char> stop;

//  ofstream image( "f:\\working\\cmakefilter.txt", ios_base::app );
//  image << '\n' << argv[1] << " begin";

    int  state = 1;

    while( !it.equal(stop) )
    {
        char ch = *it++;

        if( ch == '\n' )
        {
            state = 1;
        }
        else if( ch == '\r' )
        {
            //lose it; prevents it from resetting state
        }
        else if( ch == '#' )
        {
            if( state )state++;
        }
        else
        {
            if( state == 3 )
            {
                cout <<  "\n/// "; //doxygen
//              image << "\n/// "; //doxygen
                state++;
            }
            else if( state == 4 )
            {
                cout << ch;
//              image << ch;
            }
            else if( ch == '\t' )
            {
                //lose it; prevents it from resetting state
            }
            else if( ch == ' ' )
            {
                //lose it; prevents it from resetting state
            }
            else
            {
                state = 0;
            }
        }
    }

//  image << '\n' << argv[1] << " end\n\n";
//  image.close();

    return 0;
}


///   @}   group doxygenfilter
/// @}   group tools

